<%@page import="java.util.List"%>
<%@page import="java.sql.*"%>
<%@page import="org.barman.dao.ItemDAO"%>
<%@page import="org.barman.pojo.Item"%>

<%@include file="/layout/header.jspf"%>

<%
	String action = request.getParameter("action");
	request.setAttribute("action", action);

	String id = request.getParameter("id");
	request.setAttribute("id", id);

	String itemName = "";
	String itemPrice = "";

	if ("edit".equals(action) && Integer.parseInt(id)>0) {
		ItemDAO itemDAO = new ItemDAO();
		Item item = itemDAO.get(Integer.parseInt(id));

		itemPrice = item.getPrice().toString();
		itemName = item.getName();
	}
%>
<h1>Add/Edit Items</h1>
<br>
<form action="../ManageItemServlet?action=${action}&id=${id}" method="post">
	<table align="center">
		<tr>
			<td>Name:</td>
			<td><input name="name" type="text" value="<%=itemName%>" /></td>
		</tr>
		<tr>
			<td>Price:</td>
			<td><input name="price" type="number" value="<%=itemPrice%>" /></td>
		</tr>
		<tr>
			<td colspan="2">
			<br>
			<input type="submit" value="Save Item" />
			</td>
		</tr>
	</table>
</form>
<br>

<%@include file="/layout/footer.jspf"%>
